package io.github.annyylxyms.gyncache.command;

import io.github.annyylxyms.gyncache.core.Command;
import io.github.annyylxyms.gyncache.core.GynCache;
import io.github.annyylxyms.gyncache.core.Reply;

/**
 *
 * @author Anny
 * @date 2025/1/15 20:30
 */
public class ZcountCommand implements Command {
    @Override
    public String name() {
        return "ZCOUNT";
    }

    /**
     * 取一个范围内的元素的个数
     * @param cache
     * @param args
     * @return
     */
    @Override
    public Reply<?> exec(GynCache cache, String[] args) {
        String key = getKey(args);
        double min = Double.parseDouble(getVal(args));
        double max = Double.parseDouble(args[8]);
        return Reply.integer(cache.zcount(key, min, max));
    }
}
